package com.apobates.jforum2.troll.actionlog.mapper;

import com.apobates.jforum2.troll.actionlog.entity.TopicActionCollection;
import com.apobates.jforum2.troll.actionlog.stub.vo.TopicActionVo;
import com.apobates.jforum2.troll.utils.core.api.OptionalEntityTransformMapper;
import java.util.Optional;
import java.util.function.Function;

/**
 *
 * @author xiaofanku
 */
public class ThreadsActionVoMapperEntity implements OptionalEntityTransformMapper<TopicActionCollection, TopicActionVo>{

    @Override
    public Optional<TopicActionVo> transform(Optional<TopicActionCollection> entity) {
        return entity.map(ins->{
            return mapper().apply(ins);
        });
    }

    public static Function<TopicActionCollection,TopicActionVo> mapper(){
        return tac -> {
            TopicActionVo tav = new TopicActionVo();
            tav.setId(tac.getId());
            //话题ID
            tav.setTopicId(tac.getTopicId());
            //话题类操作时,postsId=0
            tav.setPostsId(tac.getPostsId());
            
            //会员的昵称
            tav.setMemberNickname(tac.getMemberNickname());
            //是否允许回复|是否允话评论,true(1)允许,false(0)不允许
            tav.setMemberId(tac.getMemberId());
            //动作ForumActionEnum.symbol
            tav.setAction(tac.getAction().getSymbol());
            tav.setActionTitle(tac.getAction().getTitle());
            //创建日期
            tav.setEntryDateTime(tac.getEntryDateTime());
            //IP
            tav.setIpAddr(tac.getIpAddr());
            tav.setToken(tac.getToken());
            // 角色会员等级需求
            tav.setRodeMember(tac.getRodeMember());
            return tav;
        };
    }
}